<template>
  <div class="wrapper">
    <div style="margin: 200px auto; background-color: #fff; width: 350px; height: 300px; padding: 20px; border-radius: 10px;background: rgba(200,200,200,0.6);">
      <div style="margin: 20px 0; text-align: center; font-size: 24px"><b>登 录</b></div>
      <el-form  ref="userForm">
        <el-form-item prop="name">
          <el-input size="medium" style="margin: 10px 0" prefix-icon="el-icon-user" v-model="name"></el-input>
        </el-form-item>
        <el-form-item prop="pwd">
          <el-input size="medium" style="margin: 10px 0" prefix-icon="el-icon-lock" show-password v-model="pwd"></el-input>
        </el-form-item>
        <el-form-item style="margin: 10px 0; text-align: right">
          <span style="color:red;font-size:20px;font-weight: 700;">{{msg}}</span>
          <el-button type="primary" size="small"  autocomplete="off" @click="login">登录</el-button>
          <el-button type="warning" size="small"  autocomplete="off">注册</el-button>
        </el-form-item> 
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
    data() {
        return {
            name:'zhangsan',
            pwd:'123123',
            msg:'',
            
         
        }
    },
    components: {},
    methods: {
        login(){
            
            var url="/login/login";
            
            var params=new URLSearchParams();
            
            params.append("name",this.name);
            params.append("pwd",this.pwd);
            this.$axios.post(url,params).then(resp=>{
                if(resp.data.tag){
                    this.msg='';
                    console.log(resp.data.user);
                    this.$store.dispatch("change","index");
                    this.$store.dispatch("login",resp.data.user);
                    
                }else{
                    this.msg="用户名或密码错误"
                }
            });
        }
    }
}
</script>

<style>
.wrapper {
    height: 100vh;
    background-image: linear-gradient(to bottom right, #FC466B , #3F5EFB);
    overflow: hidden;
  }
</style>
